home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / exampl_4 / frmmain.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-08-16  |  19.0 KB  |  618 lines

  1. VERSION 5.00
  2. Begin VB.Form frmMain 
  3.    Appearance      =   0  'Flat
  4.    AutoRedraw      =   -1  'True
  5.    BackColor       =   &H80000000&
  6.    BorderStyle     =   1  'Fixed Single
  7.    Caption         =   "BitBlt...and more. . . . ."
  8.    ClientHeight    =   6705
  9.    ClientLeft      =   1080
  10.    ClientTop       =   1755
  11.    ClientWidth     =   7905
  12.    ForeColor       =   &H80000008&
  13.    HelpContextID   =   10
  14.    Icon            =   "frmmain.frx":0000
  15.    KeyPreview      =   -1  'True
  16.    LinkTopic       =   "Form1"
  17.    MaxButton       =   0   'False
  18.    PaletteMode     =   1  'UseZOrder
  19.    ScaleHeight     =   6705
  20.    ScaleWidth      =   7905
  21.    StartUpPosition =   2  'CenterScreen
  22.    Begin VB.Timer tmrMain 
  23.       Interval        =   1
  24.       Left            =   1680
  25.       Top             =   480
  26.    End
  27.    Begin VB.CommandButton cmdExit 
  28.       Caption         =   "&Exit"
  29.       Height          =   375
  30.       Left            =   120
  31.       TabIndex        =   1
  32.       ToolTipText     =   "Quit"
  33.       Top             =   1080
  34.       WhatsThisHelpID =   10
  35.       Width           =   1215
  36.    End
  37.    Begin VB.PictureBox picSrc00 
  38.       Appearance      =   0  'Flat
  39.       AutoRedraw      =   -1  'True
  40.       AutoSize        =   -1  'True
  41.       BackColor       =   &H80000005&
  42.       BorderStyle     =   0  'None
  43.       BeginProperty Font 
  44.          Name            =   "MS Sans Serif"
  45.          Size            =   8.25
  46.          Charset         =   0
  47.          Weight          =   700
  48.          Underline       =   0   'False
  49.          Italic          =   0   'False
  50.          Strikethrough   =   0   'False
  51.       EndProperty
  52.       ForeColor       =   &H80000008&
  53.       Height          =   480
  54.       HelpContextID   =   270
  55.       Left            =   240
  56.       Picture         =   "frmmain.frx":0442
  57.       ScaleHeight     =   480
  58.       ScaleWidth      =   480
  59.       TabIndex        =   0
  60.       ToolTipText     =   "Bitmaps"
  61.       Top             =   360
  62.       WhatsThisHelpID =   270
  63.       Width           =   480
  64.    End
  65.    Begin VB.PictureBox picDEST 
  66.       Appearance      =   0  'Flat
  67.       AutoRedraw      =   -1  'True
  68.       AutoSize        =   -1  'True
  69.       BackColor       =   &H80000005&
  70.       BorderStyle     =   0  'None
  71.       BeginProperty Font 
  72.          Name            =   "MS Sans Serif"
  73.          Size            =   8.25
  74.          Charset         =   0
  75.          Weight          =   700
  76.          Underline       =   0   'False
  77.          Italic          =   0   'False
  78.          Strikethrough   =   0   'False
  79.       EndProperty
  80.       ForeColor       =   &H80000008&
  81.       Height          =   6135
  82.       HelpContextID   =   280
  83.       Left            =   1560
  84.       Picture         =   "frmmain.frx":1084
  85.       ScaleHeight     =   6135
  86.       ScaleWidth      =   6150
  87.       TabIndex        =   2
  88.       Top             =   360
  89.       WhatsThisHelpID =   280
  90.       Width           =   6150
  91.       Begin VB.Timer tmrBORDER 
  92.          Interval        =   1
  93.          Left            =   120
  94.          Top             =   2520
  95.       End
  96.       Begin VB.Timer tmrOFFMUSIC 
  97.          Interval        =   1
  98.          Left            =   120
  99.          Top             =   2040
  100.       End
  101.       Begin VB.Timer tmrONMUSIC 
  102.          Interval        =   1
  103.          Left            =   120
  104.          Top             =   1560
  105.       End
  106.       Begin VB.Timer tmrPOS 
  107.          Interval        =   1
  108.          Left            =   120
  109.          Top             =   1080
  110.       End
  111.       Begin VB.Timer tmrSND 
  112.          Interval        =   1
  113.          Left            =   120
  114.          Top             =   600
  115.       End
  116.    End
  117.    Begin VB.Frame Frame4 
  118.       BeginProperty Font 
  119.          Name            =   "MS Sans Serif"
  120.          Size            =   8.25
  121.          Charset         =   0
  122.          Weight          =   700
  123.          Underline       =   0   'False
  124.          Italic          =   0   'False
  125.          Strikethrough   =   0   'False
  126.       EndProperty
  127.       Height          =   6495
  128.       HelpContextID   =   340
  129.       Left            =   1440
  130.       TabIndex        =   3
  131.       Top             =   120
  132.       WhatsThisHelpID =   340
  133.       Width           =   6375
  134.    End
  135.    Begin VB.Frame Frame6 
  136.       Caption         =   "Sprites"
  137.       Height          =   855
  138.       HelpContextID   =   350
  139.       Left            =   120
  140.       TabIndex        =   4
  141.       Top             =   120
  142.       WhatsThisHelpID =   350
  143.       Width           =   1215
  144.       Begin VB.PictureBox picSrc01 
  145.          Appearance      =   0  'Flat
  146.          AutoRedraw      =   -1  'True
  147.          AutoSize        =   -1  'True
  148.          BackColor       =   &H80000005&
  149.          BorderStyle     =   0  'None
  150.          BeginProperty Font 
  151.             Name            =   "MS Sans Serif"
  152.             Size            =   8.25
  153.             Charset         =   0
  154.             Weight          =   700
  155.             Underline       =   0   'False
  156.             Italic          =   0   'False
  157.             Strikethrough   =   0   'False
  158.          EndProperty
  159.          ForeColor       =   &H80000008&
  160.          Height          =   480
  161.          HelpContextID   =   360
  162.          Left            =   600
  163.          Picture         =   "frmmain.frx":7C116
  164.          ScaleHeight     =   480
  165.          ScaleWidth      =   480
  166.          TabIndex        =   5
  167.          ToolTipText     =   "Bitmaps"
  168.          Top             =   240
  169.          WhatsThisHelpID =   360
  170.          Width           =   480
  171.       End
  172.    End
  173.    Begin VB.Label Label4 
  174.       Caption         =   "dosascii@hotmail.com"
  175.       BeginProperty Font 
  176.          Name            =   "Small Fonts"
  177.          Size            =   6
  178.          Charset         =   0
  179.          Weight          =   400
  180.          Underline       =   0   'False
  181.          Italic          =   0   'False
  182.          Strikethrough   =   0   'False
  183.       EndProperty
  184.       Height          =   255
  185.       Left            =   120
  186.       TabIndex        =   13
  187.       Top             =   6360
  188.       Width           =   1215
  189.    End
  190.    Begin VB.Line Line8 
  191.       BorderColor     =   &H80000005&
  192.       X1              =   120
  193.       X2              =   1320
  194.       Y1              =   3000
  195.       Y2              =   3000
  196.    End
  197.    Begin VB.Line Line7 
  198.       BorderColor     =   &H80000003&
  199.       BorderStyle     =   6  'Inside Solid
  200.       BorderWidth     =   2
  201.       X1              =   120
  202.       X2              =   1320
  203.       Y1              =   3000
  204.       Y2              =   3000
  205.    End
  206.    Begin VB.Label lblMUSIC 
  207.       Caption         =   "MUSIC: Off"
  208.       Height          =   255
  209.       Left            =   120
  210.       TabIndex        =   12
  211.       ToolTipText     =   "Toggle Music"
  212.       Top             =   2760
  213.       WhatsThisHelpID =   430
  214.       Width           =   1095
  215.    End
  216.    Begin VB.Label lblSFX 
  217.       Caption         =   "SFX: Off"
  218.       Height          =   255
  219.       Left            =   120
  220.       TabIndex        =   11
  221.       ToolTipText     =   "Toggle Sound Effects"
  222.       Top             =   2520
  223.       WhatsThisHelpID =   440
  224.       Width           =   1095
  225.    End
  226.    Begin VB.Label Label1 
  227.       Alignment       =   2  'Center
  228.       Caption         =   "Options:"
  229.       BeginProperty Font 
  230.          Name            =   "MS Sans Serif"
  231.          Size            =   8.25
  232.          Charset         =   0
  233.          Weight          =   700
  234.          Underline       =   -1  'True
  235.          Italic          =   0   'False
  236.          Strikethrough   =   0   'False
  237.       EndProperty
  238.       Height          =   255
  239.       Left            =   120
  240.       TabIndex        =   10
  241.       Top             =   2280
  242.       WhatsThisHelpID =   450
  243.       Width           =   1095
  244.    End
  245.    Begin VB.Line Line6 
  246.       BorderColor     =   &H80000005&
  247.       X1              =   120
  248.       X2              =   1320
  249.       Y1              =   2160
  250.       Y2              =   2160
  251.    End
  252.    Begin VB.Line Line5 
  253.       BorderColor     =   &H80000003&
  254.       BorderStyle     =   6  'Inside Solid
  255.       BorderWidth     =   2
  256.       X1              =   120
  257.       X2              =   1320
  258.       Y1              =   2160
  259.       Y2              =   2160
  260.    End
  261.    Begin VB.Line Line4 
  262.       BorderColor     =   &H80000005&
  263.       X1              =   120
  264.       X2              =   1320
  265.       Y1              =   1560
  266.       Y2              =   1560
  267.    End
  268.    Begin VB.Line Line3 
  269.       BorderColor     =   &H80000003&
  270.       BorderStyle     =   6  'Inside Solid
  271.       BorderWidth     =   2
  272.       X1              =   120
  273.       X2              =   1320
  274.       Y1              =   1560
  275.       Y2              =   1560
  276.    End
  277.    Begin VB.Label lblYPos 
  278.       Caption         =   "POS"
  279.       BeginProperty Font 
  280.          Name            =   "MS Sans Serif"
  281.          Size            =   8.25
  282.          Charset         =   0
  283.          Weight          =   700
  284.          Underline       =   0   'False
  285.          Italic          =   0   'False
  286.          Strikethrough   =   0   'False
  287.       EndProperty
  288.       Height          =   255
  289.       Left            =   360
  290.       TabIndex        =   9
  291.       Top             =   1920
  292.       WhatsThisHelpID =   500
  293.       Width           =   855
  294.    End
  295.    Begin VB.Label lblXPos 
  296.       Caption         =   "POS"
  297.       BeginProperty Font 
  298.          Name            =   "MS Sans Serif"
  299.          Size            =   8.25
  300.          Charset         =   0
  301.          Weight          =   700
  302.          Underline       =   0   'False
  303.          Italic          =   0   'False
  304.          Strikethrough   =   0   'False
  305.       EndProperty
  306.       Height          =   255
  307.       Left            =   360
  308.       TabIndex        =   8
  309.       Top             =   1680
  310.       WhatsThisHelpID =   510
  311.       Width           =   855
  312.    End
  313.    Begin VB.Label Label3 
  314.       Caption         =   "Y:"
  315.       Height          =   255
  316.       Left            =   120
  317.       TabIndex        =   7
  318.       Top             =   1920
  319.       WhatsThisHelpID =   520
  320.       Width           =   255
  321.    End
  322.    Begin VB.Label Label2 
  323.       Caption         =   "X:"
  324.       Height          =   255
  325.       Left            =   120
  326.       TabIndex        =   6
  327.       Top             =   1680
  328.       WhatsThisHelpID =   530
  329.       Width           =   255
  330.    End
  331.    Begin VB.Line Line2 
  332.       BorderColor     =   &H80000005&
  333.       X1              =   0
  334.       X2              =   7920
  335.       Y1              =   15
  336.       Y2              =   15
  337.    End
  338.    Begin VB.Line Line1 
  339.       BorderColor     =   &H80000003&
  340.       BorderStyle     =   6  'Inside Solid
  341.       BorderWidth     =   2
  342.       X1              =   0
  343.       X2              =   7920
  344.       Y1              =   0
  345.       Y2              =   0
  346.    End
  347.    Begin VB.Menu file 
  348.       Caption         =   "&File"
  349.       Begin VB.Menu exit 
  350.          Caption         =   "&Exit"
  351.       End
  352.    End
  353.    Begin VB.Menu options 
  354.       Caption         =   "&Options"
  355.       Begin VB.Menu sfx 
  356.          Caption         =   "&Sound FX"
  357.          Checked         =   -1  'True
  358.       End
  359.       Begin VB.Menu mus 
  360.          Caption         =   "&Music"
  361.          Checked         =   -1  'True
  362.       End
  363.    End
  364.    Begin VB.Menu help 
  365.       Caption         =   "&Help"
  366.       Begin VB.Menu about 
  367.          Caption         =   "&About..."
  368.          Begin VB.Menu abz 
  369.             Caption         =   "&This program..."
  370.          End
  371.       End
  372.    End
  373. Attribute VB_Name = "frmMain"
  374. Attribute VB_GlobalNameSpace = False
  375. Attribute VB_Creatable = False
  376. Attribute VB_PredeclaredId = True
  377. Attribute VB_Exposed = False
  378. Option Explicit
  379. '======================
  380. ' Sprite Information
  381. '======================
  382. 'For BitBlt.
  383. Dim XStart As Integer           'Starting X position of the sight
  384. Dim YStart As Integer           'Starting Y position of the sight
  385. Dim SightInc As Integer         'How many pixels to move the sight
  386. Dim NewXPos As Integer          'New X position of the sight
  387. Dim NewYPos As Integer          'New Y position of the sight
  388. Dim OldXPos As Integer          'Old X position of the sight
  389. Dim OldYPos As Integer          'Old Y position of the sight
  390. 'For Sound.
  391. Dim SndEnable As Boolean        'True if Sound Enabled.
  392. Dim MusicEnable As Boolean      'True if Music Enabled.
  393. 'Keys
  394. Dim UKEY As Boolean            'True if Enabled (Up Cursor)
  395. Dim DKEY As Boolean            'True if Enabled (Down Cursor)
  396. Dim LKEY As Boolean            'True if Enabled (Left Cursor)
  397. Dim RKEY As Boolean            'True if Enabled (Right Cursor)
  398. Private Sub abz_Click()
  399. 'Load About Form.
  400. frmAbout.Show vbModal, Me
  401. End Sub
  402. Private Sub exit_Click()
  403. 'Release resources.
  404. Set picSrc00 = Nothing
  405. Set picSrc01 = Nothing
  406. Set picDEST = Nothing
  407. Set frmMain = Nothing
  408. 'Close MIDI.
  409. Call mciSendString("Close All", 0&, 0, 0)
  410. Unload Me 'Shutdown.
  411. End Sub
  412. Private Sub Form_Load()
  413. 'Hide these Labels.
  414. lblXPos.Visible = False
  415. lblYPos.Visible = False
  416. 'Uncheck these values.
  417. sfx.Checked = False
  418. mus.Checked = False
  419. 'Starting Positions.
  420. XStart = 184  'Approx middle of the screen,
  421. YStart = 184   'to the top left of the sprite.
  422. OldXPos = XStart
  423. OldYPos = YStart
  424. NewXPos = OldXPos
  425. NewYPos = OldYPos
  426. SightInc = 1 'Number of pixels moved at a time. The smaller the number the smoother..
  427. 'Everything following is BitBlt.
  428. ' Paint the Mask onto the Destination using AND operator.
  429. Call BitBlt(picDEST.hDC, XStart, YStart, picSrc00.ScaleWidth \ Screen.TwipsPerPixelX, picSrc00.ScaleHeight \ Screen.TwipsPerPixelY, picSrc01.hDC, 0, 0, SRCAND)
  430. ' Paint the Source onto the Destination using XOR operator.
  431. Call BitBlt(picDEST.hDC, XStart, YStart, picSrc00.ScaleWidth \ Screen.TwipsPerPixelX, picSrc00.ScaleHeight \ Screen.TwipsPerPixelY, picSrc00.hDC, 0, 0, SRCINVERT)
  432. ' Update the screen with the updated image in memory.
  433. picDEST.Refresh
  434. picSrc00.Refresh
  435. picSrc01.Refresh
  436. End Sub
  437. Private Sub cmdExit_Click()
  438. 'Release resources.
  439. Set picSrc00 = Nothing
  440. Set picSrc01 = Nothing
  441. Set picDEST = Nothing
  442. Set frmMain = Nothing
  443. 'Close MIDI.
  444. Call mciSendString("Close All", 0&, 0, 0)
  445. Unload Me 'Shutdown.
  446. End Sub
  447. Private Sub Form_KeyDown(KEYCODE As Integer, Shift As Integer)
  448. 'Check key pressed, set flag if tracking it.
  449. Select Case KEYCODE
  450.   Case SPACE_BAR
  451.     giKeyState = giKeyState Or SPACE_BAR_FLAG
  452.   Case CURSOR_LEFT
  453.     giKeyState = giKeyState Or CURSOR_LEFT_FLAG
  454.   Case CURSOR_RIGHT
  455.     giKeyState = giKeyState Or CURSOR_RIGHT_FLAG
  456.   Case CURSOR_UP
  457.      giKeyState = giKeyState Or CURSOR_UP_FLAG
  458.   Case CURSOR_DOWN
  459.     giKeyState = giKeyState Or CURSOR_DOWN_FLAG
  460. End Select
  461. End Sub
  462. Private Sub Form_KeyUp(KEYCODE As Integer, Shift As Integer)
  463. 'Check key pressed, set flag if tracking it.
  464. Select Case KEYCODE
  465. Case SPACE_BAR
  466.     giKeyState = giKeyState And (Not SPACE_BAR_FLAG)
  467. Case CURSOR_LEFT
  468.     giKeyState = giKeyState And (Not CURSOR_LEFT_FLAG)
  469. Case CURSOR_RIGHT
  470.     giKeyState = giKeyState And (Not CURSOR_RIGHT_FLAG)
  471. Case CURSOR_UP
  472.     giKeyState = giKeyState And (Not CURSOR_UP_FLAG)
  473. Case CURSOR_DOWN
  474.     giKeyState = giKeyState And (Not CURSOR_DOWN_FLAG)
  475. End Select
  476. End Sub
  477. Sub Bitmap_Move()
  478. 'Everything following is BitBlt.
  479. 'Repaint Background(picDEST).
  480. 'picDEST is short for Picture Destation.
  481. picDEST.Cls
  482. '***------***
  483. 'Order of Ops for the call to BitBlt:
  484. 'Colour, Colour, Mask
  485. 'Colour, Colour, Colour
  486. 'AND the mask onto the work area
  487. 'Paint the Mask onto the Destination using AND operator.
  488. Call BitBlt(picDEST.hDC, NewXPos, NewYPos, picSrc00.ScaleWidth \ Screen.TwipsPerPixelX, picSrc00.ScaleHeight \ Screen.TwipsPerPixelY, picSrc01.hDC, 0, 0, SRCAND)
  489. 'Paint the Source onto the Destination using XOR operator.
  490. Call BitBlt(picDEST.hDC, NewXPos, NewYPos, picSrc00.ScaleWidth \ Screen.TwipsPerPixelX, picSrc00.ScaleHeight \ Screen.TwipsPerPixelY, picSrc00.hDC, 0, 0, SRCINVERT)
  491. OldXPos = NewXPos
  492. OldYPos = NewYPos
  493. 'Update the screen with the updated image in memory.
  494. picDEST.Refresh
  495. picSrc00.Refresh
  496. picSrc01.Refresh
  497. End Sub
  498. Private Sub mus_Click()
  499. mus.Checked = Not mus.Checked
  500. End Sub
  501. Private Sub sfx_Click()
  502. sfx.Checked = Not sfx.Checked
  503. End Sub
  504. Private Sub tmrBORDER_Timer()
  505. 'Border Dectetion.
  506. 'Very primative, please let me know if know a better way
  507. 'to do this..... dosascii@hotmail.com
  508. If NewXPos <= 0 Then
  509.    LKEY = False
  510.    LKEY = True
  511. End If
  512. If NewXPos >= 377 Then
  513.    RKEY = False
  514.    RKEY = True
  515. End If
  516. If NewYPos <= 0 Then
  517.    UKEY = False
  518.    UKEY = True
  519. End If
  520. If NewYPos >= 377 Then
  521.    DKEY = False
  522.    DKEY = True
  523. End If
  524. End Sub
  525. Private Sub tmrMain_Timer()
  526. 'This is the main loop
  527. 'Checking to see what keys are being pressed...
  528. 'Event if key is pressed...
  529. '....Move sprite if key pressed.
  530. 'If you know how to make the sprite rotate left and right,
  531. 'instead of it moving left and right, let me know.
  532. 'dosascii@hotmail.com
  533. If LKEY = True Then
  534.  If giKeyState And CURSOR_LEFT_FLAG Then
  535.     NewXPos = OldXPos - SightInc
  536.     NewYPos = OldYPos
  537.         lblXPos.Visible = True
  538.         lblYPos.Visible = True
  539.     Bitmap_Move
  540.  End If
  541. End If
  542. If RKEY = True Then
  543.  If giKeyState And CURSOR_RIGHT_FLAG Then
  544.     NewXPos = OldXPos + SightInc
  545.     NewYPos = OldYPos
  546.         lblXPos.Visible = True
  547.         lblYPos.Visible = True
  548.     Bitmap_Move
  549.     End If
  550. End If
  551. If UKEY = True Then
  552.  If giKeyState And CURSOR_UP_FLAG Then
  553.     NewXPos = OldXPos
  554.     NewYPos = OldYPos - SightInc
  555.         lblXPos.Visible = True
  556.         lblYPos.Visible = True
  557.         'Play move sound.
  558.         If SndEnable = True Then
  559.             sndPlaySound App.Path & "\move.wav", SND_ASYNC Or SND_NODEFAULT
  560.         End If
  561.     Bitmap_Move
  562.  End If
  563. End If
  564. If DKEY = True Then
  565.  If giKeyState And CURSOR_DOWN_FLAG Then
  566.     NewXPos = OldXPos
  567.     NewYPos = OldYPos + SightInc
  568.         lblXPos.Visible = True
  569.         lblYPos.Visible = True
  570.         'Play move sound.
  571.         If SndEnable = True Then
  572.             sndPlaySound App.Path & "\move.wav", SND_ASYNC Or SND_NODEFAULT
  573.         End If
  574.     Bitmap_Move
  575.  End If
  576. End If
  577. End Sub
  578. Private Sub tmrOFFMUSIC_Timer()
  579. 'Music (MIDI) Control.
  580. If MusicEnable = False Then
  581. Call mciSendString("Close All", 0&, 0, 0)
  582. End If
  583. End Sub
  584. Private Sub tmrONMUSIC_Timer()
  585. 'Music (MIDI) Control.
  586. If MusicEnable = True Then
  587.     Call mciSendString("open " + App.Path + "\track01.mid type sequencer alias track01", 0, 0, 0)
  588.     Call mciSendString("play track01", 0, 0, 0)
  589. End If
  590. 'If anyone knows how to make this loop/repeat please tell me
  591. 'dosascii@hotmail.com
  592. End Sub
  593. Private Sub tmrPOS_Timer()
  594. 'Displaying what pixel the sprite is at. Adding Plus 16 (Cos the
  595. 'sprite is 32x32 and the x&y pos is read at the top left of
  596. 'the sprite)to the Positions will fake the centre of
  597. 'the sprite.
  598. lblXPos.Caption = NewXPos + 16
  599. lblYPos.Caption = NewYPos + 16
  600. End Sub
  601. Private Sub tmrSND_Timer()
  602. 'Checking to see what values have changed in the options.
  603. 'Event on values.
  604. 'This really isn't necessary
  605. If sfx.Checked = True Then
  606. lblSFX.Caption = "SFX: On"
  607. SndEnable = True
  608. lblSFX.Caption = "SFX: Off"
  609. SndEnable = False
  610. End If
  611. If mus.Checked = True Then
  612. lblMUSIC.Caption = "MUSIC: On"
  613. MusicEnable = True
  614. lblMUSIC.Caption = "MUSIC: Off"
  615. MusicEnable = False
  616. End If
  617. End Sub
  618.